import URL from './urls.json'
import request from './request-serve-a.js'
// import store from '@/store'

// user
const login = function(params={}){
    return request.post(URL.login,params,{
        isPublic:true  // 当前请求是公开的
    })
}
const getUserList = function(params={}){
    return request.get(URL.users,{
        params:params
    })
}
const changeUserState = function(params={}){
    let tempUrl = URL.userState.replace(":uid",params.uid)
    tempUrl = tempUrl.replace(":type",params.type)
    return request.put(tempUrl)
}
const changeUserRole = function(uid="",rid=""){
    let tempUrl = URL.userRole.replace(":uid",uid)
    return request.put(tempUrl,{
        rid:rid
    })
}

// roles
const getAllRoles = function(){
    return request.get(URL.roles)
}

// right
const getMenus = function(){
    return request.get(URL.menus,{
        // headers:{
        //     Authorization:store.state.token
        // }
    })
}
const getAllRights = function(type="list"){
    let tempUrl = URL.rights.replace(":type",type)
    return request.get(tempUrl)
}

// 商品
// 参数
const getCategoriesList = function(params={}){
    return request.get(URL.categories,{
        params:params
    })
    // return request.get(`categories/${params.id}`,{
    //     params:params
    // })
}

//数据报告
const getReports = function(typeId="1"){
    let tempUrl = URL.reports.replace(":typeId",typeId)
    return request.get(tempUrl)
}

const api = {
    // users
    login,getUserList,changeUserState,changeUserRole,
    // roles
    getAllRoles,
    // rights
    getMenus,getAllRights,
    // goods
    getCategoriesList,
    getReports
}
export default {
    ...api,
    install(Vue){
        Vue.prototype.$api = api;
        Vue.prototype.$URL = URL;
    }
}